package com.cunyme;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class ForumPost extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.forum_post);
        // Set up login button and login listener
		Button myPostButton = (Button)findViewById(R.id.post_button);
	    myPostButton.setOnClickListener(myPostButtonListener);        
        // Set up skip button and login listener
		Button myCancelButton = (Button)findViewById(R.id.cancel_button);
	    myCancelButton.setOnClickListener(myCancelButtonListener);        
    }
    OnClickListener myPostButtonListener = new OnClickListener()
	{
		public void onClick(View v)
		{
			// TODO Auto-generated method stub
			// Take what user types in text boxes and assigns it to strings
			EditText titleEdit = (EditText)findViewById(R.id.title);
			EditText bodyEdit = (EditText)findViewById(R.id.body);
			EditText nameEdit = (EditText)findViewById(R.id.name);
			String titleString = titleEdit.getText().toString();
			String bodyString = bodyEdit.getText().toString();
			String nameString = nameEdit.getText().toString();
			
	        try { 
	        	Document page = Jsoup.connect("http://s88157295.onlinehome.us/forum/commentadd.php")
	        	.data("poster", nameString, "postemail", "q@q.q", "posttitle", titleString, "posttxt", bodyString, "assume", "true")
	        	.post();
        	} catch (IOException e) {  
        		e.printStackTrace();
        	}			
	        // Going to main menu
			Intent gotoForum = new Intent(ForumPost.this, Forum.class);
			startActivity(gotoForum);
			finish();
		}
    };
    OnClickListener myCancelButtonListener = new OnClickListener()
	{
		public void onClick(View v)
		{
			// TODO Auto-generated method stub
	        // Going to main menu
//			Intent gotoForum = new Intent(ForumPost.this, Forum.class);
//			startActivity(gotoForum);
			finish();
		}
    };
}
